package com;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
小孩班级名单统计
 */
public class DemoApplication {
    private static List<String> ALL_STUDENT_NAME_LIST = Arrays.asList(
            "22张尚明珠","11张语沫","籍彦哲","朱若晗", "甘允芮"
    );

    public static void main(String[] args) {
        System.out.println("1111");
        List<String> list = extractNamesFromFile("D:\\workspace\\springboot-demo\\src\\main\\java\\com\\zs\\demo\\names.txt");
        int i = 1;
        for(String name : ALL_STUDENT_NAME_LIST){
            if(!list.contains(name)){
                System.out.println((i++)+" "+name);
                System.out.println(name);
            }
        }
    }
    public static List<String> extractNamesFromFile(String fileName) {
        List<String> names = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            String line;
            while ((line = br.readLine()) != null) {
                line=line.replace(" ","");
                // 使用正则表达式来匹配名字
                Pattern pattern = Pattern.compile("[\\p{L}]+");
                Matcher matcher = pattern.matcher(line);
                while (matcher.find()) {
                    String name = matcher.group();
                    String tmp = name;
                    name = name.replace("妈","")
                            .replace("爸", "")
                            .replace("爷", "")
                            .replace("奶", "")
                            .replace("阿姨", "")
                            .replace("已买", "")
                            .replace("已交", "");
                    if(names.contains(name)){
                        System.out.println("重复登记："+name);
                    }else{
//                        System.out.println(name);
                        names.add(name);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return names;
    }
}
